package com.atguigu.gmall;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 李旭
 * @date 2021/11/20 16:17
 * @Description:
 *
 *   异步编排    线程间通信
 */
public class CompletableFutureDemo {


    public static void main(String[] args) {

        //自定义线程池
        ThreadPoolExecutor threadPoolExecutor = new
                ThreadPoolExecutor(
                    5,//核心线程
                    10,//最大线程数
                    3,
                 TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10)
        );
        //1:开启第一个线程
    /*    CompletableFuture.runAsync(() -> {
            //   ForkJoinPool.commonPool-worker-1
            System.out.println(Thread.currentThread().getName());
        });  */
        CompletableFuture.runAsync(() -> {
            //  pool-1-thread-1
            System.out.println(Thread.currentThread().getName());
        },threadPoolExecutor);

        CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            //return "fsfsdfs";
            return 1234;// 返回类型是U 任意类型的
        },threadPoolExecutor);

        //Runnable    |   Callable 接口
    }
}
